package com.cloudcc.mobile.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.cloudcc.cloudframe.util.ConnectivityUtils;
import com.cloudcc.cloudframe.util.PackageUtils;
import com.cloudcc.mobile.manager.RunTimeManager;

/**
 * 网络变化广播 只要网络能发生变化 就发出广播
 * 
 * @author wangzhiqiang
 * @date 2015-6-9 上午10:54:36
 * 
 */
public class NetStateChangedReceiver extends BroadcastReceiver {
	@SuppressWarnings("static-access")
	@Override
	public void onReceive(Context context, Intent intent) {

		// 只有在 运行的时候 才检测
		boolean foreGround = PackageUtils.isForeGround(context,
				context.getPackageName());
		if (!foreGround) {
			return;
		}
		if ("en".equals(RunTimeManager.getInstance().getlanguage())) {
			if (ConnectivityUtils.hasInternet(context)) {
				Toast.makeText(context, "The network status is currently on", 0).show();
			} else {
				Toast.makeText(context, "There is currently no network, please check the network settings", 0).show();
			}
		}else{
			if (ConnectivityUtils.hasInternet(context)) {
				Toast.makeText(context, "当前开启网络状态", 0).show();
			} else {
				Toast.makeText(context, "当前暂无网络，请检查网络设置", 0).show();
			}
		}
		
	}

}
